package com.example.lanouhn.firstapp.activity.utils;


import com.alibaba.fastjson.JSON;
import com.example.lanouhn.firstapp.activity.model.BrokerDealer;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * JSON解析自营按钮跳转的页面数据
 * Created by lanouhn on 16/7/19.
 */
public class BrokerdealerJson {

    /**
     * 解析自营按钮跳转商城页面商品列表
     *
     * @param json
     * @return
     */
    public static List<BrokerDealer> getBrokerdealer(String json) {
        //创建数组来储存数据
        List<BrokerDealer> list = new ArrayList<>();

        try {
            //获取解析的数据
            JSONObject obj = new JSONObject(json);
            String data = obj.getString("datas");
            //获取解析的数据
            JSONObject job = new JSONObject(data);
            String data1 =job.getString("goods_list_info");
            //解析数据
            JSONObject jsonObject = new JSONObject(data1);
            JSONArray array = jsonObject.getJSONArray("recommended_goods_list");

            //使用fastjson解析
            list = new ArrayList<BrokerDealer>
                    (JSON.parseArray(array.toString(), BrokerDealer.class));

        } catch (JSONException e) {
            e.printStackTrace();
        }
        return list;

    }
}
